<!--数据字典管理-->
<template>
  <div>
    <a-card>
      <p slot="title">
        检索条件
      </p>
      <div class="formSearch">
        <a-form ref="entryDTO" :label-width="80" layout="inline"
                @keydown.native.enter.prevent="handleSubmit">
          <a-form-item label="订单名称：" prop="searchKey">
            <a-input v-model="searchKey" placeholder="请输入订单名称"
                     @keyup="formatEnterContent(searchKey)"
                     @blur="formatEnterContent(searchKey)" style="width: 220px">
              <a-icon slot="prefix" type="user" class="displayPre" />
              <a-icon v-if="searchKey" slot="suffix" type="close-circle" @click="emitEmpty(searchKey)" />
            </a-input>
          </a-form-item>
          <a-button type="primary" @click="handleSubmit"
                    >查询
          </a-button>
          <a-button style="margin-left: 8px" @click="reStore">重置</a-button>
        </a-form>
      </div>
    </a-card>
    <div style="height: 10px"></div>
    <div class="commonStyle nyContent">
      <div class="table-operator" v-if="hasPermission ('material:entry:save')">
        <a-button type="primary"  @click="addDTO" >新增</a-button>
      </div>
      <a-table :columns="columns" :dataSource="entryManagePageData" :rowKey="record => record.recordId"
               :pagination="false">
                <span slot="index" slot-scope="text, record, index">
                    {{ (page.currentPage - 1) * page.pageSize + index + 1 }}
                </span>
        <span slot="useState" slot-scope="text, record, index" :style="{color:(text === '1'?'#00ff00':'#000000')}">
                    {{ text === '0'?'未使用':(text === '1'?'在用':'未知')}}
                </span>
        <span slot="operation" slot-scope="text, record, index" class="table-operation">
                         <a @click="info(record)" v-if="hasPermission ('material:entry:info')">
                            详情</a>
          <a @click="editDTO(record)" v-if="hasPermission ('material:entry:save')">
                            编辑</a>
                        <a @click="deleteDTO(record)" v-if="hasPermission ('material:entry:delete')">
                                          删除</a>
                </span>
      </a-table>
      <Page :totalCount="pageVal.total" :currentPage="pageVal.currentPage" ref="page"
            :pageSize="pageVal.pageSize" @changePage="changePage" @changePageSize="changePageSize" />
    </div>
    <add-edit ref="addEdit"
              :title="title"
              :objDTO="objDTO" @init="init" />
    <entry-info ref="entryInfo"/>
  </div>
</template>

<script>
import addEdit from './addEdit.vue'
import entryInfo from './entryInfo.vue'
import { mapState } from 'vuex'
import Page from 'module/pagination'
import Util from '@/libs/util';
export default {
  name: 'entryManage',
  components: {
    addEdit,
    entryInfo,
    Page,
  },
  data () {
    return {
      title: true,
      searchKey: '',
      selectedNode: {id: '', name: ''},
      array: [ 10, 20, 30, 40 ],
      /*选中的记录*/
      selectedRowKeys: [],
      objDTO: {
        recordId: '',
        name: '',
        buildName: '',
        buildCode: '',
        roomCode: '0',
        diskNum: '',
      },
      page: {
        currentPage: 1,
        pageSize: 10
      },
      columns: [
        {title: '序号', key: 'index', width: '8%', align: 'center', scopedSlots: {customRender: 'index'}},
        {title: '订单名称', dataIndex: 'orderName', key: 'orderName', width: '10%'},
        {title: '订单编号', dataIndex: 'orderCode', key: 'orderCode', width: '10%'},
        {title: '收货时间', dataIndex: 'receiveTime', key: 'receiveTime', width: '10%'},
        {title: '所在位置', dataIndex: 'location', key: 'location', width: '8%'},
        {title: '在用状态', dataIndex: 'useState', key: 'useState', width: '15%',scopedSlots: {customRender: 'useState'}},
        {title: '入账人', dataIndex: 'entryPersion', key: 'entryPersion', width: '15%',},
        {title: '入账时间', dataIndex: 'entryTime', key: 'entryTime', width: '15%',},
        {title: '操作', key: 'operation', width: '16%', scopedSlots: {customRender: 'operation'}}
      ],
    }
  },
  computed: {
    entryManagePageData () {
      return this.$store.state.entryManage.entryManagePageData
    },
    ...mapState ({
      pageVal: state => state.entryManage.page,
    }),

  },
  filters: {
    filterWord(value, list) {
      for (let i=0; i<list.length; i++) {
        if (value === list[i].value) {
          return list[i].label
        }
      }
    },
  },
  methods: {
    emitEmpty () {
      this.searchKey = ''
      this.init ()
    },
    reStore(){
      this.searchKey = ''
      this.page.currentPage = 1
      this.init();
    },

    editDTO(Obj){
      this.objDTO = {...Obj}
      this.title = false
      this.$refs.addEdit.showEdit(this.objDTO)
    },
    info(Obj){
      this.objDTO = {...Obj}
      this.$refs.entryInfo.showModal(this.objDTO)
    },
    addDTO(){
      this.clearDTO ()
      this.title = true
      this.$refs.addEdit.showModal ()
    },
    clearDTO(){
      this.objDTO= {
        recordId: '',
            name: '',
            buildName: '',
            buildCode: '',
            roomCode: '0',
            diskNum: '',
      }
    },
    /*
     * 过滤输入框输入的特殊字符
     * */
    formatEnterContent ( value ) {
      let a = Util.clearSpecialChart(value);
      this.searchKey = a
    },

    /**
     * Function    : init
     * Description : 初始化列表
     * Input       : none
     * Return      : none
     */
    init () {
      let para = Object.assign ({},
          {name: this.searchKey.trim ()}, this.page)
      this.$store.dispatch ('getEntryManagePageListAct', para)
      this.$store.commit ('setEntryManageQueryPrams', para)
    },



    /**
     * Function    : delRole
     * Description : 批量删除角色
     * Input       : none
     * Return      : none
     */
    deleteDTO (obj) {
      this.$confirm ({
        title: '确认删除【'+obj.orderName+'】的入账记录吗？',
        okText: '确定',
        cancelText: '取消',
        onOk: () => {
          let _this = this
          this.$store.dispatch ('deleteEntryAct', {recordId: obj.recordId}).then (response => {
            if (response.code === 0) {
              _this.init ()
              this.$message.success (response.message)
            } else {
              this.$message.error (response.message)
            }
          })
        },
      })
    },


    /**
     * Function    : changePage
     * Description : 切换页码
     * Input       : val
     * Return      : none
     */
    changePage ( val ) {
      this.page.currentPage = val
      this.init ()
    },

    /**
     * Function    : changePageSize
     * Description : 切换每页条数
     * Input       : vm
     * Return      : none
     */
    changePageSize ( vm ) {
      this.page.pageSize = vm
      this.page.currentPage = 1
      this.init ()
    },

    /**
     * Function    : handleSubmit
     * Description : 查询按钮
     * Input       : none
     * Return      : none
     */
    handleSubmit () {
      this.page.currentPage = 1
      this.init ()
    },


  },
  created () {
    this.searchKey = this.$route.query.searchKey === undefined ? '' : this.$route.query.searchKey
    this.page.currentPage = this.$route.query.currentPage === undefined ? 1 : this.$route.query.currentPage
    this.page.pageSize = this.$route.query.pageSize === undefined ? 10 : this.$route.query.pageSize
    this.init ()
  },
  mounted () {

  }
}
</script>
